<script LANGUAGE="javascript">
<!--
function verificarSalvar() 
{
    var theCPF = document.formulario.clie_cpf_cnpj;
    if (theCPF.value == "")
    {
      alert("Preencha o campo CPF/CNPJ");
      theCPF.focus();
      return (false);
    }
    if (((theCPF.value.length == 11) && (theCPF.value == 11111111111) || (theCPF.value == 22222222222) || (theCPF.value == 33333333333) || (theCPF.value == 44444444444) || (theCPF.value == 55555555555) || (theCPF.value == 66666666666) || (theCPF.value == 77777777777) || (theCPF.value == 88888888888) || (theCPF.value == 99999999999) || (theCPF.value == 00000000000))) 
    {
      alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
      theCPF.focus();
      return (false);
    }
    if (!((theCPF.value.length == 11) || (theCPF.value.length == 14)))
    {
      alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
      theCPF.focus();
      return (false);
    }
    var checkOK = "0123456789";
    var checkStr = theCPF.value;
    var allValid = true;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      }
      allNum += ch;
    } 
    if (!allValid) 
    {
      alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
      theCPF.focus();
      return (false);
    }

    var chkVal = allNum;
    var prsVal = parseFloat(allNum);
    if (chkVal != "" && !(prsVal > "0"))
    {
      alert("CPF zerado. Por favor, preencha novamente o campo.");
      theCPF.focus();
      return (false);
    }
    if (theCPF.value.length == 11)
    {
      var tot = 0;
      for (i = 2;  i <= 10;  i++)
        tot += i * parseInt(checkStr.charAt(10 - i));
      if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9)))
      {
        alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
        theCPF.focus();
        return (false);
      }

      tot = 0;

      for (i = 2;  i <= 11;  i++)
        tot += i * parseInt(checkStr.charAt(11 - i));

      if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10)))
      {
        alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
        theCPF.focus();
        return (false);
      }
    }
    else
    {
      var tot  = 0;
      var peso = 2;

      for (i = 0;  i <= 11;  i++)
      {
        tot += peso * parseInt(checkStr.charAt(11 - i));
        peso++;
        if (peso == 10)
        {
            peso = 2;
        }
      }

      if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12)))
      {
        alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
        theCPF.focus();
        return (false);
      }

      tot  = 0;
      peso = 2;

      for (i = 0;  i <= 12;  i++)
      {
        tot += peso * parseInt(checkStr.charAt(12 - i)) 
        peso++;
        if (peso == 10)
        {
            peso = 2;
        }
      }
      if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13)))
      {
        alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
        theCPF.focus();
        return (false);
      }
    }
    // return(true);
}
//-->
</script>
<?php echo $html->script('validar'); ?>
<div class="wrapper">
    <br><br>
    <div class="leadsCtn">
        <div class="title">
                <h4 class="left">Editar cliente</h4>
                 <div class="right" style="vertical-align: middle; margin-right: 10px; margin-top: 10px">
                <?php echo $html->link('Visualizar usuários deste cliente', '/usuario/index/search:'.$objCliente->clie_empresa, array( 'class' => 'botaoCinza right peq' )); ?>
            </div>
        </div>
        <div class="content bMargin-7">
            <?php $url_form = ($removidos) ? '/cliente/editar/'.$objCliente->clie_id.'/removidos' : '/cliente/editar/'.$objCliente->clie_id; ?>
            <form name="formulario" method="post" action="<?php echo Mapper::url($url_form); ?>">
                <fieldset class="left">
                    <ul class="form vhh a">
                        <li>
                            <label>Nome:</label>
                            <input type="text" name="clie_nome" class="required" label="Nome" value="<?php echo $objCliente->clie_nome; ?>"/>
                        </li>
                        <li>
                            <label>E-mail:</label>
                            <input type="text" name="clie_email" class="email" label="E-mail" value="<?php echo $objCliente->clie_email; ?>"/>
                        </li>
                        <li>
                            <label>Telefone:</label>
                            <input type="text" name="clie_telefone" class="telefone" label="Telefone" value="<?php echo $objCliente->clie_telefone; ?>"/>
                        </li>
                        <li class="bMargin-7">
                            <label>Celular:</label>
                            <input type="text" name="clie_celular" class="telefone" label="Celular" value="<?php echo $objCliente->clie_celular; ?>"/>
                        </li>
                        <li>
                            <label>Empresa:</label>
                            <input type="text" name="clie_empresa" class="required"  label="Empresa" value="<?php echo $objCliente->clie_empresa; ?>"/>
                        </li>
                        <li>
                            <label>CPF/CNPJ:</label>
                            <input type="text" name="clie_cpf_cnpj" class="required" label="CPF/CNPJ" value="<?php echo $objCliente->clie_cpf_cnpj; ?>"/>
                        </li>
                        <li>
                            <label>Endereço:</label>
                            <input type="text" name="clie_endereco" class="required" label="Endereço" value="<?php echo $objCliente->clie_endereco; ?>"/>
                        </li>
                        <li>
                            <label>Cidade:</label>
                            <input type="text" name="clie_cidade" class="required" label="Cidade" value="<?php echo $objCliente->clie_cidade; ?>"/>
                        </li>
                        <li>
                            <label>Estado:</label>
                            <select name="clie_estado">
                                <option value="AC" <?php if($objCliente->clie_estado == "AC") echo "selected='selected'"; ?>>Acre</option>
                                <option value="AL" <?php if($objCliente->clie_estado == "AL") echo "selected='selected'"; ?>>Alagoas</option>
                                <option value="AP" <?php if($objCliente->clie_estado == "AP") echo "selected='selected'"; ?>>Amapá</option>
                                <option value="AM" <?php if($objCliente->clie_estado == "AM") echo "selected='selected'"; ?>>Amazonas</option>
                                <option value="BA" <?php if($objCliente->clie_estado == "BA") echo "selected='selected'"; ?>>Bahia</option>
                                <option value="CE" <?php if($objCliente->clie_estado == "CE") echo "selected='selected'"; ?>>Ceará</option>
                                <option value="DF" <?php if($objCliente->clie_estado == "DF") echo "selected='selected'"; ?>>Distrito Federal</option>
                                <option value="ES" <?php if($objCliente->clie_estado == "ES") echo "selected='selected'"; ?>>Espírito Santo</option>
                                <option value="GO" <?php if($objCliente->clie_estado == "GO") echo "selected='selected'"; ?>>Goiás</option>
                                <option value="MA" <?php if($objCliente->clie_estado == "MA") echo "selected='selected'"; ?>>Maranhão</option>
                                <option value="MT" <?php if($objCliente->clie_estado == "MT") echo "selected='selected'"; ?>>Mato Grosso</option>
                                <option value="MS" <?php if($objCliente->clie_estado == "MS") echo "selected='selected'"; ?>>Mato Grosso do Sul</option>
                                <option value="MG" <?php if($objCliente->clie_estado == "MG") echo "selected='selected'"; ?>>Minas Gerais</option>
                                <option value="PA" <?php if($objCliente->clie_estado == "PA") echo "selected='selected'"; ?>>Pará</option>
                                <option value="PB" <?php if($objCliente->clie_estado == "PB") echo "selected='selected'"; ?>>Paraíba</option>
                                <option value="PR" <?php if($objCliente->clie_estado == "PR") echo "selected='selected'"; ?>>Paraná</option>
                                <option value="PE" <?php if($objCliente->clie_estado == "PE") echo "selected='selected'"; ?>>Pernambuco</option>
                                <option value="PI" <?php if($objCliente->clie_estado == "PI") echo "selected='selected'"; ?>>Piauí</option>
                                <option value="RJ" <?php if($objCliente->clie_estado == "RJ") echo "selected='selected'"; ?>>Rio de Janeiro</option>
                                <option value="RN" <?php if($objCliente->clie_estado == "RN") echo "selected='selected'"; ?>>Rio Grande do Norte</option>
                                <option value="RS" <?php if($objCliente->clie_estado == "RS") echo "selected='selected'"; ?>>Rio Grande do Sul</option>
                                <option value="RO" <?php if($objCliente->clie_estado == "RO") echo "selected='selected'"; ?>>Rondônia</option>
                                <option value="RR" <?php if($objCliente->clie_estado == "RR") echo "selected='selected'"; ?>>Roraima</option>
                                <option value="SC" <?php if($objCliente->clie_estado == "SC") echo "selected='selected'"; ?>>Santa Catarina</option>
                                <option value="SP" <?php if($objCliente->clie_estado == "SP") echo "selected='selected'"; ?>>São Paulo</option>
                                <option value="SE" <?php if($objCliente->clie_estado == "SE") echo "selected='selected'"; ?>>Sergipe</option>
                                <option value="TO" <?php if($objCliente->clie_estado == "TO") echo "selected='selected'"; ?>>Tocantins</option>
                            </select>
                        </li>
                    </ul>
                </fieldset>
                <fieldset class="right">
                    <ul class="form b right">
                        <li>
                            <input type="hidden" name="plan_id_antigo" value="<?php echo $objCliente->plan_id;?>"/>
                            <label>Plano:</label>
                             <select name="plan_id" class="left">
                                <?php
                                   foreach($arrPlano as $objPlano)
                                   {
                                       $objPlano = (object) $objPlano;
                                       echo "<option value='".$objPlano->plan_id;
                                       if($objCliente->plan_id == $objPlano->plan_id)
                                           echo "' selected='selected";
                                       echo "'>".$objPlano->plan_nome." de valor R$".$objPlano->plan_valor.",00</option>";
                                   }
                               ?>
                            </select>
                        </li>
                        <li>
                            <label>Empresa de acesso:</label>
                            <input type="text" name="clie_url_acesso" label="Empressa de acesso" class="required" value="<?php echo $objCliente->clie_url_acesso; ?>"/>
                        </li>
                        <li>
                            <label>Status:</label>
                            <select name="clie_status" class="left">
                                <option value="1" <?php if($objCliente->clie_status == "1") echo "selected='selected'"; ?>>Ativo</option>
                                <option value="0" <?php if($objCliente->clie_status == '0') echo "selected='selected'"; ?>>Inativo</option>
                                <option value="2" <?php if($objCliente->clie_status == '2') echo "selected='selected'"; ?>>Excluido</option>
                            </select>
                        </li>
                    </ul>
                    <div class="clear"></div>
                    <?php
                    /* VER REGRA 
                    <ul class="form hhh bMargin-3 right">
                        <li>
                                <input type="radio" name="" value="" />
                                <label type="text" for="">Test Drive 7 dias</label>
                        </li>
                        <li>
                                <input type="radio" name="" value="" />
                                <label type="text" for="">Test Drive 15 dias</label>
                        </li>
                        <li>
                                <input type="radio" name="" value="" />
                                <label type="text" for="">Test Drive 30 dias</label>
                        </li>
                    </ul>
                    <div class="clear"></div>
                    <ul class="form hhh tar c right bMargin-3">
                        <li>
                                <label for="">Início</label>
                                <input type="text" name="clie_data_inicio" value="<?php echo implode( '/', array_reverse( explode( '-', $objCliente->clie_data_inicio ) ) ); ?>" />
                        </li>
                        <li>
                                <label for="">Término</label>
                                <input type="text" name="clie_data_fim" value="<?php echo implode( '/', array_reverse( explode( '-', $objCliente->clie_data_fim ) ) ); ?>" />
                        </li>
                    </ul>
                    <li>
                            <label for="">Valor do plano:</label>
                            <input type="text" name="clie_valor" value="<?php echo $objCliente->clie_valor; ?>" />
                    </li>
                    <li>
                            <label for="">Nº Usuários:</label>
                            <input type="text" name="clie_max_usua" value="<?php echo $objCliente->clie_max_usua; ?>" />
                    </li>
                    <li>
                            <label for="">Qtd. Leads:</label>
                            <input type="text" name="clie_max_lead" value="<?php echo $objCliente->clie_max_lead; ?>" />
                    </li>
                    <li>
                            <label for="">Qtd. Campanhas:</label>
                            <input type="text" name="clie_max_camp" value="<?php echo $objCliente->clie_max_camp; ?>" />
                    </li>
                    */
                    ?>			
                    <input type="submit" class="right botaoCinza" value="Salvar" onmousedown="verificarSalvar()"/>
                </fieldset>
            </form>
        </div><!-- .content -->
    </div><!-- .leads -->
</div><!-- .wraper -->